package todo.core.bso;

import java.util.List;

import todo.core.dao.TodoDAO;
import todo.core.domain.Todo;


public class TodoServiceImpl implements TodoService {
	
	private TodoDAO todoDAO = null;

	public TodoServiceImpl() {
		super();
	}
	
	/* (non-Javadoc)
	 * @see todo.core.bso.TodoService#findAll()
	 */
	public List<Todo> findAll() {
		return todoDAO.findAll();
	}
	
	/* (non-Javadoc)
	 * @see todo.core.bso.TodoService#save(todo.core.domain.Todo)
	 */
	public Todo save(Todo transientInstance) {
		todoDAO.save(transientInstance);
		return transientInstance;
	}

	/* (non-Javadoc)
	 * @see todo.core.bso.TodoService#update(todo.core.domain.Todo)
	 */
	public Todo update(Todo instance) {
		todoDAO.attachDirty(instance);
		return instance;
	}

	
	/* (non-Javadoc)
	 * @see todo.core.bso.TodoService#delete(todo.core.domain.Todo)
	 */
	public void delete(Todo detachedPersistentInstance) {
		Todo persistentInstance = findById(detachedPersistentInstance.getTodoId());
		todoDAO.delete(persistentInstance);
	}


	public void setTodoDAO(TodoDAO todoDAO) {
		this.todoDAO = todoDAO;
	}

	/* (non-Javadoc)
	 * @see todo.core.bso.TodoService#findById(java.lang.String)
	 */
	public Todo findById(String id) {
		Todo persistentInstance = todoDAO.findById(id);
		return persistentInstance;
	}
}
